<?php
/*
 * 公共文件，任何php请求都需要经过
 */

@session_start();
define('APP_ROOT', str_replace("\\", '/', substr(dirname(__FILE__),0,-7)));
define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
set_include_path(APP_ROOT.'include/');
set_magic_quotes_runtime(0);

require 'config.inc.php';
require 'global.func.php';
include_once 'siteconf.class.php';
$site_conf = new siteconf(APP_ROOT . 'site.conf');
require 'db.class.php';
include_once 'session.class.php';
include_once 'response.class.php';
include_once 'file.func.php';
include_once 'log.class.php';
include_once 'template.class.php';
include_once 'hook.class.php';
include_once 'moduleconf.class.php';
$response = new response();
$session = new session();
$log = new log();
if(DEBUG)
{
    if(XDEBUG_FLAG == 1)
    {
        xdebug_start_code_coverage();
    }
    error_reporting(E_ALL);
}
else
{
    error_reporting(0);
}

$db = new db($db_conf);


$hook_obj = new hook();
$mconf = new moduleconf();
define('IP', ip());
$db->prepare('select count(*) as nums from edufe_ip_count where ip=?');
$db->set_string(IP);
$ip_res_count = $db->execute(true);
if($ip_res_count['nums'] <= 0)
{
    $db->prepare('insert into edufe_ip_count (ip) values (?)');
    $db->set_string(IP);
    $db->execute();
    $db->simple_update('edufe_count', array('id'=>1), array('id'=>1), 'count=count+1');
}
define('TIME', time());
define('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
define('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : preg_replace("/(.*)\.php(.*)/i", "\\1.php", $_SERVER['PHP_SELF']));
define('QUERY_STRING', safe_replace($_SERVER['QUERY_STRING']));
define('PATH_INFO', isset($_SERVER['PATH_INFO']) ? safe_replace($_SERVER['PATH_INFO']) : '');
define('DOMAIN', isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : preg_replace("/([^:]*)[:0-9]*/i", "\\1", $_SERVER['HTTP_HOST']));
define('SCHEME', $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');
define('SITE_URL', SCHEME.$_SERVER['HTTP_HOST'].APP_PATH);
// define('SITE_URL', $site_conf->get('SITE_URL'));
define('RELATE_URL', isset($_SERVER['REQUEST_URI']) ? safe_replace($_SERVER['REQUEST_URI']) : SCRIPT_NAME.(QUERY_STRING ? '?'.QUERY_STRING : PATH_INFO));
define('URL', SCHEME.$_SERVER['HTTP_HOST'].RELATE_URL);
define('RELATE_REFERER',urlencode(RELATE_URL));
$ishtml = false;
$CATEGORY = cache_read('CACHE_ALL_CATEGORY');
$base_dir = APP_PATH;
$self_dir = dirname(SCRIPT_NAME);
$self_dir = substr($self_dir,0,strlen($base_dir)) == $base_dir ? substr($self_dir, strlen($base_dir)) : $self_dir;
$self_url = SCRIPT_NAME;
if(function_exists('date_default_timezone_set')) date_default_timezone_set(TIMEZONE);
header('Content-type: text/html; charset=' . CHARSET);
if($_REQUEST)
{
	if(MAGIC_QUOTES_GPC)
	{
		if(isset($_GET) && is_array($_GET))
		{
			$_GET = new_stripslashes($_GET);
		}
		if(isset($_POST) && is_array($_POST))
		{
			$_POST = new_stripslashes($_POST);
		}
		if(isset($_COOKIE) && is_array($_COOKIE))
		{
			$_COOKIE = new_stripslashes($_COOKIE);
		}
	}
	if(isset($_POST) && is_array($_POST))
	{
		extract($_POST);
	}
	if(isset($_GET) && is_array($_GET))
	{
		extract($_GET);
	}
	if(isset($_COOKIE) && is_array($_COOKIE))
	{
		extract($_COOKIE);
	}
}
?>
